$(function() {
	admin.activityBase.init();
});
Namespace('admin.activityBase', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	
	receive:function(id) {
		var url = contextPath + '/activity/base/receive';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('操作成功');
				top.addTab("1",'活动列表', contextPath+'/activity/base/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	unclaimed:function(id) {
		var url = contextPath + '/activity/base/unclaimed';
        $('#datagrid').datagrid('loading');
		$.post(url, {id:id}, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('操作成功');
				top.addTab("1",'活动列表', contextPath+'/activity/base/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	toDelete:function (id) {
		var tip = "确定要删除吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/activity/base/delete';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					top.addTab("1",'活动列表', contextPath+'/activity/base/list');
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	/**
	 * 推荐活动
	 */
	recommend: function (id) {
		var orderIndex = prompt("请输入推荐位置【1-99越小位置越靠前】:","1");
		if (orderIndex != null){
			var url = contextPath + '/activity/base/recommend';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id,'recommendOidx':orderIndex}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('推荐成功');
					var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
					admin.activityBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});
		}else{
			top.showInfo('请输入推荐位置');
		}
	},
	/**
	 * 取消推荐活动
	 */
	unRecommend: function (id) {
        var url = contextPath + '/activity/base/unRecommend';
		$('#datagrid').datagrid('loading');
		$.post(url, {'id': id}, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('操作成功');
				var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
				admin.activityBase.query();
			} else {
				top.showInfo(result.msg);
			}
		});
	},
});